const mongoose = require("mongoose");
const DB_URL = "mongodb://localhost:27017/job_react";

mongoose.connect(DB_URL);

const models = {
  user: {
    username: {type: String, required: true},
    pwd: {type: String, required: true},
    role: {type: String, required: true},
    avatar: {type: String},// 头像
    phone: {type: String},// 电话
    desc: {type: String}, // genius
    job: {type: String},
    company: {type: String},//boss
    salary: {type: String} //boss
  },
  chat: {
    chatId: {type: String},
    from: {type: String},
    to: {type: String},
    content: {type: String},
    read: {type: Boolean, default: false},
    create_time: {type: String, default: new Date().getTime()}
  }
};

for (let name in models) {
  mongoose.model(name, new mongoose.Schema(models[name]));
}

module.exports = {
  getModel: function (name) {
    return mongoose.model(name)
  }
};